﻿@{
    ViewBag.Title = "UpgradeWorkingTime";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script>
    var Editing_ysList = []; //编辑域中的人员
    $(function () {
        $('#zls').click(function () {
            var initIdSelected = "";
            $.each(Editing_ysList,
                function () {
                    initIdSelected += this.id + ",";
                });
            $.modalOpen({
                id: "StaffCorrelation",
                title: "选择治疗师",
                url: "/SystemManage/SysStaff/Selector?single=true&isContansChildOrg=false&callbackType=json&dutyCode=RehabDoctor&initIdSelected=" + initIdSelected,
                showleftlalbel: false,
                width: "650px",
                height: "570px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick(function (data) {
                        staffTreeCallback(data);
                    });
                }
            });
        });

        init();
        gridList();

    });

    function gridList() {
        var $gridList = $("#HisgridList");
        $gridList.dataGrid({
            url: "/TherapeutistManage/NonChargeableItems/GetStaffHourList",
            shrinkToFit: false,
            postData: getSearchPostData(),
            height: $(window).height() - 185,
            colModel: [
                { label: "主键", name: "id", hidden: true, key: true },
                { label: '工号', name: 'ysgh', width: 50, align: 'left' },
                { label: '治疗师姓名', name: 'NAME', width: 80, align: 'left' },
                { label: '年份', name: 'syear', width: 80, align: 'left' },
                {
                    label: '月份', name: 'smonth', width: 80, align: 'left',
                    formatter: function (cellvalue) {
                        return parseInt(cellvalue) < 10 ? "0" + cellvalue : cellvalue
                    }
                },
                {
                    label: '总时长(H)', name: 'sc', width: 80, align: 'left', formatter: function (cellvalue, options, rowObject) {
                        return (rowObject.sc / 60).toFixed(2) + "小时";
                    }
                }
            ],
            pager: "#gridPager",
            sortname: 'desc',
            rowNum: '100',
            viewrecords: true
        });
        $("#btn_search").click(function () {
            $gridList.jqGrid('setGridParam',
                {
                    postData: getSearchPostData(),
                    url: "/TherapeutistManage/NonChargeableItems/GetStaffHourList"
                }).trigger('reloadGrid');
        });
        $gridList.closest(".ui-jqgrid-bdiv").css({ 'overflow-x': 'hidden' });
    }

    function getSearchPostData() {
        var postData = {};
        postData.year = $('#Year').val();
        postData.month = $('#Month').val();
        postData.ysgh = "";
        if (!postData.year || !postData.month) {
            return;
        }
        if (Editing_ysList.length > 0) {
            postData.ysgh = Editing_ysList[0].gh;
        }
        return postData;
    }

    //人员树 选择 回调
    function staffTreeCallback(treeSeleData) {
        Editing_ysList = [];
        var zlsNames = "";
        $.each(treeSeleData, function () {
            zlsNames += this.text + ",";
            Editing_ysList.push({ id: this.id, gh: this.value, Name: this.text, ks: this.Ex1, ksmc: this.Ex2 });
        })
        if (zlsNames.length > 0) {
            zlsNames = zlsNames.substring(0, zlsNames.length - 1);
        }

        $('#zls').val(zlsNames);
    }

    function init() {
        var date = new Date();
        //年份
        $("#Year").newtouchBindSelect({
            datasource: function () {
                var resultObjArr = new Array();
                if (top.clients.yearArr && top.clients.yearArr.length) {
                    $.each(top.clients.yearArr, function () {
                        resultObjArr.push({ id: this, text: this });
                    });
                }
                return resultObjArr;
            },
            selectedValue: 1900 + date.getYear(),
        });
        //月份
        $("#Month").newtouchBindSelect({
            datasource: function () {
                var resultObjArr = new Array();
                if (top.clients.monthArr && top.clients.monthArr.length) {
                    $.each(top.clients.monthArr, function () {
                        resultObjArr.push({ id: this, text: parseInt(this) < 10 ? "0" + this : this });
                    });
                }
                return resultObjArr;
            },
            selectedValue: date.getMonth() + 1,
        });

        $("#ks").newtouchBindSelect({
            datasource: function () {
                var resultObjArr = new Array();
                $.each(top.window.clients.sysDepartList, function (idx, val) {
                    resultObjArr.push({ id: val.Code, text: val.Name });
                });
                return resultObjArr;
            }
        });
    }

    function btn_edit() {
        var seleRowid = jQuery("#HisgridList").jqGrid("getGridParam", "selrow");
        if (!(seleRowid)) {
            $.modalAlert("请先选中一条信息", "warning");
            return;
        }
        var data = $("#HisgridList").jqGridRowValue();
        localStorage.setItem("needupdateData", JSON.stringify(data));
        $.modalOpen({
            id: "Form",
            title: "调整时长",
            url: "/TherapeutistManage/NonChargeableItems/UpdateView",
            width: "700px",
            height: "600px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
</script>
<form id="form1">
    <div class="panel panel-default" style="margin-top:5px;">
        <div class="panel-heading navb-bg">
            筛选条件
        </div>
        <div style="padding: 2px; padding-right: 20px;">
            <table class="form">
                <tr>
                    <td class="formTitle">年份：</td>
                    <td class="formValue">
                        <select id="Year" class="form-control">
                            <option value="-1">===请选择===</option>
                        </select>
                    </td>
                    <td class="formTitle">月份：</td>
                    <td class="formValue">
                        <select id="Month" class="form-control">
                            <option value="-1">===请选择===</option>
                        </select>
                    </td>
                    @*<th class="formTitle">科室：</th>
                        <td class="formValue">
                            <select id="ks" class="form-control">
                                <option value="-1">===请选择===</option>
                            </select>
                        </td>*@
                    <th class="formTitle">治疗师：</th>
                    <td class="formValue">
                        <input id="zls" type="text" class="form-control" />
                    </td>
                    <td class="formValue" colspan="3">
                        <input type="button" id="btn_search" class="btn btn-primary" style="width: 50px; margin-left: 40px;" value="查询" />
                        <input type="button" class="btn btn-primary" onclick="btn_edit()" style="width: 55px; margin-left: 40px;" value="调整时长" />
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <div class="gridPanel" id="tabGrid">
        <table id="HisgridList" rel="tabGrid"></table>
        <div id="gridPager" rel="form1"></div>
    </div>
</form>
